package com.uphone.kingmall.activity.order;

import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.china.zhuoyue.R;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.uphone.kingmall.adapter.RvOrderFollowAdapter;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.bean.FollowInfoBean;
import com.uphone.kingmall.listener.onNormalRequestListener;
import com.uphone.kingmall.utils.GsonUtils;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.OkGoUtils;
import com.uphone.kingmall.utils.intent.IntentData;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 孙增艳
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2019/2/26
 *     desc   : 订单物流跟踪
 *     version: 1.0
 * </pre>
 */
public class OrderFollowActivity extends BaseActivity {
    @BindView(R.id.tv_order_number)
    TextView tvOrderNumber;
    @BindView(R.id.tv_order_company)
    TextView tvOrderCompany;
    @BindView(R.id.rv_order_follow)
    RecyclerView rvOrderFollow;
    @IntentData
    private int id = -1;
    private RvOrderFollowAdapter followAdapter;

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_order_follow;
    }

    @Override
    public void initView() {
        rvOrderFollow.setLayoutManager(new LinearLayoutManager(OrderFollowActivity.this));
    }

    @Override
    public void initData() {
        HttpParams params = new HttpParams();
        params.put("orderId", id);
        OkGoUtils.progressRequest(MyUrl.getOrderSendInfo, this, params, new onNormalRequestListener() {
            @Override
            public void onSuccess(String body, int code) {
                if (code == 0) {
                    FollowInfoBean bean = GsonUtils.getGson().fromJson(body, FollowInfoBean.class);
                    tvOrderNumber.setText("订单号：" + bean.getSendNo());
                    tvOrderCompany.setText("承运人：" + bean.getSendCo());

                    followAdapter = new RvOrderFollowAdapter(OrderFollowActivity.this, bean.getSendInfo().getState());
                    rvOrderFollow.setAdapter(followAdapter);
                    followAdapter.setNewData(bean.getSendInfo().getTraces());
                }
            }

            @Override
            public void onError(Response<String> response) {

            }
        });
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
